package com.ruoyi.produce.process.defective.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.process.defective.domain.Defective;
import com.ruoyi.produce.process.defective.service.IDefectiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Drj 2021/12/20
 */
@RestController
@RequestMapping("/produce/defective")
@Api(value = "次品模块", tags = "次品接口")
public class DefectiveController extends BaseController {
    @Autowired
    private IDefectiveService defectiveService;
    /**
     * 获取次品记录列表
     * @param defective
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("获取次品记录列表")
    public TableDataInfo list(@RequestBody Defective defective){
        startPage();
        List<Defective> defectiveList = defectiveService.selectDefectiveList(defective);

        return getDataTable(defectiveList);
    }

    /**
     * 导出员工绩效表单
     * @param defective
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody Defective defective)
    {
        List<Defective> defectiveList = defectiveService.selectDefectiveList(defective);
        ExcelUtil<Defective> util = new ExcelUtil<>(Defective.class);
        return util.exportExcel(defectiveList, "员工绩效表单");
    }


    /**
     * 新增次品记录
     * @param defective
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增次品记录")
    public AjaxResult add(@RequestBody  Defective defective){
        System.out.println(defective);

        return toAjax(defectiveService.insertDefective(defective));
    }

    /**
     * 修改次品记录
     * @param defective
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation("修改次品记录")
    public AjaxResult edit(@RequestBody  Defective defective)
    {
        return toAjax(defectiveService.updateDefective(defective));
    }

    /**
     * 删除次品记录
     * 仅修改删除标志位
     * @param defective
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除次品记录")
    public AjaxResult delete(@RequestBody  Defective defective)
    {

        return toAjax(defectiveService.deleteDefective(defective));
    }
}
